(function(){
	var dizhi =$(".dizhi"),
		xinzeng=$(".btn_32"),
		table=$("table"),
		gwlc4=$(".gwlc4"),
		mask=$(".woddz_mask"),
		mask_x=$("#mask_x"),
		save=$("#baocun"),
		o5_no=$("#o5_no"),
		o5_dele=$("#o5_dele"),
		kuang=$(".kuang"),
		shanchu2=$("#shanchu2"),
		chacha=$("#chacha"),
		querenshanchu=$("#querenshanchu"),
		mask2_shanchu=$("#o5_ok"),
		mask2_quxiao=$("#o5_no"),
		mask2=$("#shanchu1");
		dizhi.each(function(i){	
			$(this).on("click",function(){
				dizhi.removeClass("kuang");
				$(this).addClass("kuang");
			})
		});
		xinzeng.on("click",function(){
			mask.css("display","block");
		})
		mask_x.on("click",function(){
			mask.css("display","none");
		})
		save.on("click",function(){
			mask.css("display","none");
		})
	//省市 区三级联动
$(function() {
	var pro = $("#pro"),
			city_name = $("#city"),
			direct_id = $("#direct"),
			xuanzechengshi=$("#xuanzechengshi"),
			xuanzediqu=$("#xuanzediqu");
			/*点击空白的时候加上请选择地区和选择城市*/
			var li_city="<li>请选择城市</li>";
			city_name.append(li_city);
			var li_direct="<li>请选择地区</li>";
			direct_id.append(li_direct);
		$.each(province, function(k, p) {
			var li = "<li data-id='" + p.ProID + "'>" + p.ProName + "</li>";
			pro.append(li);
			
		});
		$("#pro li").on("click", function() {
			$("#city li").remove();
			$("#direct li").remove();
			/*清楚城市以及地区的值**/
			xuanzechengshi.val("");
			xuanzediqu.val("");
			var pro_val = $(this).data("id");
			$.each(city, function(k, p) {
				if(p.ProID == pro_val) {
					var li = "<li data-id='" + p.CityID + "'>" + p.CityName + "</li>";
					city_name.append(li);
				}
			});
		});
		$("#city").on("click", "li", function() {
			$("#direct li").remove();
			xuanzediqu.val("");
			/*点击请选择城市的时候加上请选择地区*/
			var li_direct="<li>请选择地区</li>";
			direct_id.append(li_direct);
			var city_val = $(this).data("id");
			$.each(District, function(k, p) {
				if(p.CityID == city_val) {
					var li = "<li data-id='" + p.ID + "'>" + p.DisName + "</li>";
					direct_id.append(li);
				}
			});
		})
});
	$(function(){
		var i=0,
		textarea=$("textarea"),
		zishu=$(".baifenbai a"),
		area_val="";
			textarea.on("keyup",function(){
				var textarea_val=textarea.val();
				if(textarea[0].value==''){
					zishu.text("0");
				}else{
					var reg = /[\u4e00-\u9fa5\w]/g;
					if(textarea_val.match(reg).length>100){
						textarea_val=area_val;
					}else{
						area_val=textarea_val;
						zishu.text(area_val.length);
					}
				}
			});
	});
	/*弹窗部分js代码*/
	/**文本域部分的提示*/
	var textarea_tishi=$(".tishi"),
		textarea=$("textarea");
		textarea.on("focus",function(){
			textarea_tishi.css("opacity","0");
		})
		textarea.on("blur",function(){
			var textarea_val=$("textarea").val();
			if(textarea_val.length==0){
				textarea_tishi.css("opacity","1");
			}
		})
	/****邮编地址****/
	var youbian_tishi=$(".youdiquhao"),
		youbian_input=$("#youbiandizhi");
	youbian_input.on("focus",function(){
		youbian_tishi.css("opacity","0");
		youbian_input.val("");
		youbian_input.css("color","#000000");
	})
	youbian_input.on("blur",function(){
		var youbian_val=$("#youbiandizhi").val();
		var r3=/^[0-9]{6}$/;
		if(r3.test(youbian_val)==false){
			youbian_tishi.css("opacity","1");
			youbian_input.val("请输入6位数字");	
			youbian_input.css("color","#eb413d");
		}
	})	
	/***点击修改页面的时候弹窗*****/
	var xiugai =$(".woddz_xiugai");
	for(var i=0;i<xiugai.length;i++){
			xiugai.eq(i).on("click",function(){
				mask.css("display","block");
			})
	}
	/***点击删除页面的时候弹窗*****/
	var shanchu =$(".woddz_shanchu");
	for(var i=0;i<shanchu.length;i++){
			shanchu.eq(i).on("click",function(){
				var that =this;
				mask2.css("display","block");
				querenshanchu.text("确定要删除该地址，删除后将不可恢复。");
				mask2_shanchu.on("click",function(){
					shanchu2.css("display","block");
					o5_no.on("click",function(){
						mask2.css("display","none");
					})
					chacha.on("click",function(){
						shanchu2.css("display","none");
						mask2.css("display","none");
					})
					$(that).parent().parent().remove();
//					var xinshezhi=$(that).parent().parent().next(":last-child");
					var xinshezhi=$(that).parent().parent();
					console.log(xinshezhi[0]);
//					xinshezhi.children().addClass(".kuang");/**如果是默认设置则把下一个变成默认设置**/
				})
				o5_dele.on("click",function(){
					mask2.css("display","none");
				})
			})
	}
				mask2_quxiao.on("click",function(){
					mask2.css("display","none");
				})
})();
